﻿using CalendarWindowsApp.Controls.Calendar;
using Windows.System;
using Windows.UI.Xaml.Controls;

namespace CalendarWindowsApp.Behaviors
{
    public class AddAppointmentBehavior : BehaviorBase
    {
        protected override void OnAttached()
        {
            base.OnAttached();
            var textBox = this.AssociatedObject as TextBox;
            textBox.KeyDown += (s, e) =>
            {
                if (e.Key == VirtualKey.Enter)
                {
                    var day = textBox.DataContext as Day;
                    day.AddAppointment(textBox.Text);
                    textBox.Text = string.Empty;
                    day.IsSelected = false;
                }
            };
        }
    }
}